package com.hqyj.controller;


import com.hqyj.pojo.TbComplaint;
import com.hqyj.service.TbComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 投诉表 前端控制器
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/tb-complaint")
public class TbComplaintController {

    @Autowired
    TbComplaintService tbComplaintService;


    /**
     * 新增
     * http://localhost:8080/tb-complaint/add
     * {"communityName":"蓝雾苑", "communityId":"2", "ownerId":"3","ownerName":"王五","description":"半夜施工扰民",
     * "reason":"噪音","createTime":"2021-09-27 09:51:42","updateTime":"2021-09-27 09:51:42","status":"0"}
     *
     * @param tbComplaint
     * @return
     */
    @PostMapping(value = "/add", consumes = "application/json")
    public HashMap<String, Object> add(@RequestBody TbComplaint tbComplaint) {
        return tbComplaintService.add(tbComplaint);
    }


    /**
     * 修改
     * http://localhost:8080/tb-complaint/update
     * {"id":"4","ownerId":"4","ownerName":"刘六","updateTime":"2021-09-27 10:26:50","status":"1"}
     *
     * @param tbComplaint
     * @return
     */
    @PutMapping(value = "/update", consumes = "application/json")
    public HashMap<String, Object> update(@RequestBody TbComplaint tbComplaint) {
        return tbComplaintService.update(tbComplaint);
    }


    /**
     * 删除
     * http://localhost:8080/tb-complaint/del/?
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public HashMap<String, Object> del(@PathVariable Integer id) {
        return tbComplaintService.del(id);
    }

    /**
     * 查询
     * http://localhost:8080/tb-complaint/list?page=1&row=2
     *
     * @param tbComplaint
     * @return
     */
    @GetMapping("/list")
    public HashMap<String, Object> list(TbComplaint tbComplaint) {
        return tbComplaintService.list(tbComplaint);
    }

    /**
     * 通过姓名查询投诉
     * http://localhost:8080/tb-complaint/ownerName?ownerName=张三
     *
     * @param ownerName
     * @return
     */
    @GetMapping("/ownerName")
    public HashMap<String, Object> ownerName(String ownerName) {
        return tbComplaintService.ownerName(ownerName);
    }
}

